home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / a56v12st.lzh / a56 / examples / chorus.lis < prev    next >
Encoding:
File List  |  1994-09-02  |  16.6 KB  |  406 lines

  1.               ;***************************************************************
  2.               ; 
  3.               ; Stereo chorus for the DSP56001 signal processor.
  4.               ; Developed by Quinn Jensen (jensenq@qcj.icon.com).
  5.               ; 
  6.               ; This program fragment implements a stereo "chorus" effect
  7.               ; on a DSP56001 processor.  Chorus adds depth and warmth to
  8.               ; sound by creating the illusion that more instruments
  9.               ; are involved in the sound than really are.  It does this by
  10.               ; mixing together a delayed version of the input with the input
  11.               ; itself.  This program uses the following signal flow.
  12.               ;
  13.               ;
  14.               ;  Left in ------+------- "dry" gain -----------> sum -----> Left out
  15.               ;                |                                 ^
  16.               ;                v                                 |
  17.               ;               sum --> delay ---> "wet" gain -----+
  18.               ;                ^                                 |
  19.               ;                |                                 v -
  20.               ;  Right in -----+------- "dry" gain -----------> sum -----> Right out
  21.               ;
  22.               ;
  23.               ; Note that the delay line output is negated before summing with the
  24.               ; right input signal.  This throws in 180 degrees of phase shift
  25.               ; making for interesting results even with mono inputs 
  26.               ; (i.e. Left in == Right in).
  27.               ; 
  28.               ; Chorus uses a delay time of between about 10 and 50ms in some commercial
  29.               ; units.  This program can be configured for longer delays.
  30.               ; In the chorus effect, the delay time is slowly varied, adding a very
  31.               ; subtle pitch shift.  The depth and speed of the delay-time modulation
  32.               ; are adjustable to taste.  The greater the depth or speed, the greater
  33.               ; the coloration of the signal.
  34.               ;
  35.               ; Variations in this algorithm are possible and encouraged.  I came
  36.               ; up with this code after studying the impulse response and characteristics
  37.               ; of a commercial stereo chorus pedal and reading various articles in magazines
  38.               ; and on usenet over the years.  My somewhat dry TX81 synthesizer sounds pretty
  39.               ; good with this and other effects I run on the 56001.
  40.               ;
  41.               ; A recent article with a pretty good not-too-technical overview of chorus 
  42.               ; and other effects:  Gary Hall, "From the Top: Effects, the Essential Musical
  43.               ; Spice," _Electronic Musician_, August 1991, pp. 62-68.
  44.               ;
  45.               ; I would enjoy seeing any improvements to the code.
  46.               ;
  47.               include "tdsg.a56"      ;hardware specific initialization code
  48.               
  49.               ;***************************************************************
  50.               ;
  51.               ;       Data and constants
  52.               ;
  53.               ;***************************************************************
  54.               
  55. P:0076        dot                             ;remember where we were in P-space
  56. X:0020                org     x:$20           ;put runtime variables in on-chip X-space
  57.               
  58.               ; A spreadsheet was used to calculate the following numbers
  59.               
  60.               ; Sample rate              32.5500 kc         
  61.               ; 
  62.               ; Delay time (4-52)        28.0000 ms           delay time knob
  63.               ; Depth (1-10)             10.0000              depth knob (I like it deep)
  64.               ; Speed (1-10)              0.0000              speed knob (I like it slow)
  65.               ; 
  66.               ; max depth +/-            24.0000 ms         
  67.               ; min delay                 4.0000 ms         
  68.               ; max delay                52.0000 ms         
  69.               ; 1/2 cycle period          5.0000 s          
  70.               ; samples per 1/2 cyc  162750.0000
  71.               ; time delta/samp           0.2949 us         
  72.               ; offset samp/samp          0.0096
  73.               ; 
  74. FFFF7E          doff_i equ                              -130  ;initial delay offset (tap)
  75.     0.0096      ddeltaf equ                           0.0096  ;delta-delay, per sample
  76. 027BBE          dspeed_i equ                          162750  ;number of samples per
  77.                                                               ;half cycle of triangle wave
  78.                                                               ;delay-time modulator
  79.               ; 
  80.               ; Delay time (ms)              tap                   tap     delay
  81.               ; 
  82.               ;                   1      32.5500                     1      0.03
  83.               ;                   2      65.1000                     2      0.06
  84.               ;                   4     130.2000                     4      0.12
  85.               ;                   5     162.7500                     8      0.25
  86.               ;                   8     260.4000                    16      0.49
  87.               ;                  10     325.5000                    32      0.98
  88.               ;                  20     651.0000                    64      1.97
  89.               ;                  25     813.7500                   128      3.93
  90.               ;                  40    1302.0000                   256      7.86
  91.               ;                  50    1627.5000                   512     15.73
  92.               ;                  60    1953.0000                  1024     31.46
  93.               ;                  70    2278.5000                  2048     62.92
  94.               ;                  80    2604.0000                  4096    125.84
  95.               ;                  90    2929.5000                  8192    251.67
  96.               ;                 100    3255.0000                 16384    503.35
  97.               
  98.               ;
  99.               ;       The delay line is in off-chip X memory
  100.               ;
  101. 002000        delay   equ     $2000
  102. 001000        dmax    equ     4096            ;125 ms (probably way too long)
  103.               ;
  104.               ; doff and ddelta are 48-bit quantities
  105.               ;
  106. X:0020 FFFF7E doff    dc      doff_i          ;current delay distance
  107. Y:0020                org     y:doff
  108. Y:0020 000000         dc      0
  109.               
  110. X:0021                org     x:doff+1
  111. X:0021 000000 ddelta  dc      0               ;delta delay per sample
  112. Y:0021                org     y:ddelta
  113. Y:0021 013A93         dc      ddeltaf
  114.               
  115. X:0022                org     x:ddelta+1
  116.               
  117. X:0022 027BBE dspeed  dc      dspeed_i        ;samples per half cycle of triangle modulator
  118. X:0023 000000 dtoggle dc      0               ;current sample count
  119. X:0024        delayout
  120. X:0024 000000         dc      0               ;current delay-line output
  121.               
  122. Y:0000                org     y:$0
  123.               
  124. P:0076                org     p:dot           ;go back to P-space
  125.               ;***************************************************************
  126.               ;
  127.               ; Initialization code
  128.               ;
  129.               ;***************************************************************
  130. P:0076        hf_init
  131. P:0076 61F400         move    #delay,r1                       ;delay line input
  132. P:0077 002000
  133. P:0078 05F421         movec   #dmax-1,m1                      ;
  134. P:0079 000FFF
  135. P:007A 71F400         move    #doff_i,n1                      ;distance to output
  136. P:007B FFFF7E
  137. P:007C 00000C         rts
  138.               ;
  139.               ;***************************************************************
  140.               ;
  141.               ;       Sample-rate computations.  Call chorus_compute at
  142.               ;       interrupt time when both left and right inputs are
  143.               ;       ready.
  144.               ;
  145.               ;       fs = 32.552083 kHz
  146.               ;
  147.               ;       x:<in_l         left-channel input
  148.               ;       x:<in_r         right-channel input
  149.               ;       x:<out_l        left-channel output
  150.               ;       x:<out_r        right-channel output
  151.               ;
  152.               ;***************************************************************
  153.               
  154. P:007D        hf_comp
  155. P:007D 0D0066         jsr     <saveregs
  156.               ;
  157.               ;       output and input mix
  158.               ;
  159. P:007E 253813         clr     a       #.4375,x1               ;clr a, get input scale
  160. P:007F 27401B         clr     b       #.5,y1                  ;clr b, get output scaler
  161.               
  162. P:0080 46A400         move            x:<delayout,y0          ;get delay out
  163.               
  164. P:0081 4480BB         macr    y0,y1,b x:<in_l,x0              ;b = .5 * delay, x0=in_l
  165. P:0082 21E6CB         macr    x0,y1,b         b,y0            ;b += .5 * in_l, y0=b
  166. P:0083 5704A3         macr    x0,x1,a b,x:<out_l              ;a = x1 * in_l, L = b
  167. P:0084 20CF00         move                    y0,b            ;b = -y0
  168. P:0085 44813E         neg     b       x:<in_r,x0              ;x0 = in_r
  169. P:0086 2000CB         macr    x0,y1,b                         ;b += .5 * in_r
  170. P:0087 5705A3         macr    x0,x1,a b,x:<out_r              ;R = b, a += x1 * in_r
  171.               ;
  172.               ;       delay line in
  173.               ;
  174. P:0088 565900         move    a,x:(r1)+
  175.               ;
  176.               ;       delay line length modulation.  A simple triangle-wave modulator
  177.               ;       is used.  A sine-wave modulator would be much better, especially
  178.               ;       with deeper and/or faster settings.
  179.               ;
  180. P:0089 48A000         move            l:<doff,a               ;a = current offset
  181. P:008A 42A100         move            l:<ddelta,x             ;x = current delta
  182. P:008B 200020         add     x,a
  183. P:008C 482000         move            a,l:<doff               ;new offset = a + x
  184. P:008D 219900         move            a1,n1
  185.               
  186. P:008E 20AF00         move            x1,b                    ;save delta for later use
  187.               ;
  188.               ; smoothly transition between delay-line offsets by
  189.               ; interpolating the current sample with the previous or next
  190.               ; one depending on whether the delay is currently getting longer or
  191.               ; shorter.  Otherwise, an obnoxious click results when the offset snaps
  192.               ; to the next integral value.  This does have a low-pass effect on the
  193.               ; delayed signal path but it is not objectionable.
  194.               ;
  195. P:008F 5EA000         move                    y:<doff,a       ;compute |frac(doff)|
  196. P:0090 44F423         lsr     a       #$800000,x0
  197. P:0091 800000
  198. P:0092 254042         or      x0,a    #.5,x1
  199. P:0093 218400         move            a1,x0
  200. P:0094 2000A4         mpy     -x0,x1,a
  201. P:0095 21C60B         tst     b               a,y0            ;y0 = 0.5 * |frac(doff)|
  202. P:0096 0AF0A3         jpl     shorter                         ;on positive delta, the
  203. P:0097 0000A1
  204.                                                               ;delay is shortening
  205.               
  206. P:0098 205100         move            (r1)-                   ;get previous sample
  207. P:0099 44E900         move            x:(r1+n1),x0
  208. P:009A 2F40D0         mpy     y0,x0,a #.5,b                   ;scale
  209. P:009B 20595C         sub     y0,b    (r1)+                   ;compute scale for cur sample
  210. P:009C 21E600         move                    b,y0
  211. P:009D 44E900         move            x:(r1+n1),x0            ;get cur sample
  212. P:009E 2000D2         mac     x0,y0,a                         ;scale and sum
  213. P:009F 0AF080         jmp     endpan
  214. P:00A0 0000A7
  215.               
  216. P:00A1        shorter
  217. P:00A1 44E900         move            x:(r1+n1),x0            ;get cur sample
  218. P:00A2 2F40D0         mpy     y0,x0,a #.5,b                   ;scale
  219. P:00A3 20595C         sub     y0,b    (r1)+                   ;compute scale for next sample
  220. P:00A4 21E600         move                    b,y0
  221. P:00A5 44E900         move            x:(r1+n1),x0            ;get next sample
  222. P:00A6 2051D2         mac     x0,y0,a (r1)-                   ;scale and sum
  223. P:00A7        endpan
  224. P:00A7 562400         move            a,x:<delayout           ;store resulting output
  225.               ;
  226.               ; update the triangle wave modulation (sinewave would be better)
  227.               ;
  228. P:00A8 56A300         move            x:<dtoggle,a            ;decrement toggle count
  229. P:00A9 44F400         move            #>1,x0
  230. P:00AA 000001
  231. P:00AB 200044         sub     x0,a
  232. P:00AC 562300         move            a,x:<dtoggle
  233. P:00AD 0AF0A7         jgt     notogg                          ;time to toggle?
  234. P:00AE 0000B3
  235. P:00AF 44A200         move            x:<dspeed,x0            ;yes, negate delta and reset
  236. P:00B0 48A100         move            l:<ddelta,a
  237. P:00B1 442336         neg     a       x0,x:<dtoggle
  238. P:00B2 482100         move            a,l:<ddelta
  239. P:00B3        notogg
  240. P:00B3        bypass
  241. P:00B3 0D006F         jsr     <restregs
  242. P:00B4 00000C         rts
  243.               
  244.                       end
  245.  
  246. Summary of psect usage
  247.  
  248.                  section seg base last top      used       avail    total
  249. -------------------------------------------------------------------------
  250.  
  251.  
  252. Symbol Table
  253. -------------------------------------
  254.           ddelta 000021
  255.          ddeltaf 0.0096000000
  256.          ssi_int 000061
  257.             ssix 000010
  258.           notogg 0000B3
  259.         delayout 000024
  260.            delay 002000
  261.      init_stereo 000059
  262.            start 000040
  263.            in_rs 000003
  264.            in_ls 000002
  265.             in_r 000001
  266.             in_l 000000
  267.             dmax 001000
  268.           endpan 0000A7
  269.             doff 000020
  270.           doff_i FFFF7E
  271.              dot 000076
  272.         mainloop 000060
  273.          hf_comp 00007D
  274.          hf_init 000076
  275.          dtoggle 000023
  276.         saveregs 000066
  277.            savey 00000B
  278.            savex 00000A
  279.           saveb2 000009
  280.          saveb10 000008
  281.           savea2 000007
  282.          savea10 000006
  283.           dspeed 000022
  284.         dspeed_i 027BBE
  285.         restregs 00006F
  286.            out_r 000005
  287.            out_l 000004
  288.           bypass 0000B3
  289.          shorter 0000A1
  290.           m_scl1 00000F
  291.           m_scl0 00000E
  292.            m_scl 00C000
  293.           m_ssl1 00000D
  294.           m_ssl0 00000C
  295.            m_ssl 003000
  296.           m_hpl1 00000B
  297.           m_hpl0 00000A
  298.            m_hpl 000C00
  299.           m_ibl2 000005
  300.           m_ibl1 000004
  301.           m_ibl0 000003
  302.            m_ibl 000038
  303.           m_ial2 000002
  304.           m_ial1 000001
  305.           m_ial0 000000
  306.            m_ial 000007
  307.            m_ipr 00FFFF
  308.            m_rdf 000007
  309.            m_tde 000006
  310.            m_roe 000005
  311.            m_tue 000004
  312.            m_rfs 000003
  313.            m_tfs 000002
  314.            m_if1 000001
  315.            m_if0 000000
  316.             m_if 000002
  317.           m_srie 00000F
  318.           m_stie 00000E
  319.            m_sre 00000D
  320.            m_ste 00000C
  321.            m_mod 00000B
  322.            m_gck 00000A
  323.            m_syn 000009
  324.            m_fsl 000008
  325.           m_sckd 000005
  326.           m_scd2 000004
  327.           m_scd1 000003
  328.           m_scd0 000002
  329.            m_scd 00001C
  330.            m_of1 000001
  331.            m_of0 000000
  332.             m_of 000003
  333.            m_psr 00000F
  334.            m_wl1 00000E
  335.            m_wl0 00000D
  336.             m_wl 006000
  337.             m_dc 001F00
  338.             m_pm 0000FF
  339.            m_tsr 00FFEE
  340.             m_sr 00FFEE
  341.            m_crb 00FFED
  342.            m_cra 00FFEC
  343.             m_tx 00FFEF
  344.             m_rx 00FFEF
  345.            m_tcm 00000F
  346.            m_rcm 00000E
  347.            m_scp 00000D
  348.            m_cod 00000C
  349.             m_cd 000FFF
  350.             m_r8 000007
  351.             m_fe 000006
  352.             m_pe 000005
  353.             m_or 000004
  354.           m_idle 000003
  355.           m_rdrf 000002
  356.           m_tdre 000001
  357.           m_trne 000000
  358.           m_tmie 00000D
  359.            m_tie 00000C
  360.            m_rie 00000B
  361.           m_ilie 00000A
  362.             m_te 000009
  363.             m_re 000008
  364.           m_woms 000007
  365.            m_rwi 000006
  366.           m_wake 000005
  367.            m_sbk 000004
  368.           m_wds2 000002
  369.           m_wds1 000001
  370.           m_wds0 000000
  371.            m_wds 000003
  372.           m_sccr 00FFF2
  373.            m_ssr 00FFF1
  374.            m_scr 00FFF0
  375.           m_stxa 00FFF3
  376.           m_stxh 00FFF6
  377.           m_stxm 00FFF5
  378.           m_stxl 00FFF4
  379.           m_srxh 00FFF6
  380.           m_srxm 00FFF5
  381.           m_srxl 00FFF4
  382.            m_dma 000007
  383.            m_hf1 000004
  384.            m_hf0 000003
  385.             m_hf 000018
  386.            m_hcp 000002
  387.           m_htde 000001
  388.           m_hrdf 000000
  389.            m_hf3 000004
  390.            m_hf2 000003
  391.           m_hcie 000002
  392.           m_htie 000001
  393.           m_hrie 000000
  394.            m_htx 00FFEB
  395.            m_hrx 00FFEB
  396.            m_hsr 00FFE9
  397.            m_hcr 00FFE8
  398.            m_pcd 00FFE5
  399.          m_pcddr 00FFE3
  400.            m_pcc 00FFE1
  401.            m_pbd 00FFE4
  402.          m_pbddr 00FFE2
  403.            m_pbc 00FFE0
  404.            m_bcr 00FFFE
  405. errors=0
  406.